home *** CD-ROM | disk | FTP | other *** search
/ Champak 147 / (Vol 147) Jan 21 2012.iso / Interface / it.dig / scripts / __Packages / mx / controls / ComboBox.as < prev    next >
Text File  |  2012-01-21  |  14KB  |  466 lines

  1. class mx.controls.ComboBox extends mx.controls.ComboBase
  2. {
  3.    static var symbolName = "ComboBox";
  4.    static var symbolOwner = mx.controls.ComboBox;
  5.    static var version = "2.0.0.377";
  6.    var clipParameters = {labels:1,data:1,editable:1,rowCount:1,dropdownWidth:1};
  7.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.ComboBox.prototype.clipParameters,mx.controls.ComboBase.prototype.clipParameters);
  8.    var className = "ComboBox";
  9.    var _showingDropdown = false;
  10.    var __rowCount = 5;
  11.    var dropdownBorderStyle = undefined;
  12.    var initializing = true;
  13.    var __labelField = "label";
  14.    var bInKeyDown = false;
  15.    function ComboBox()
  16.    {
  17.       super();
  18.    }
  19.    function init()
  20.    {
  21.       super.init();
  22.    }
  23.    function createChildren()
  24.    {
  25.       super.createChildren();
  26.       this.__set__editable(this.editable);
  27.       if(this.__labels.length > 0)
  28.       {
  29.          var _loc6_ = new Array();
  30.          var _loc3_ = 0;
  31.          while(_loc3_ < this.labels.length)
  32.          {
  33.             _loc6_.addItem({label:this.labels[_loc3_],data:this.data[_loc3_]});
  34.             _loc3_ = _loc3_ + 1;
  35.          }
  36.          this.setDataProvider(_loc6_);
  37.       }
  38.       this.__set__dropdownWidth(typeof this.__dropdownWidth != "number" ? this.__width : this.__dropdownWidth);
  39.       if(!this._editable)
  40.       {
  41.          this.selectedIndex = 0;
  42.       }
  43.       this.initializing = false;
  44.    }
  45.    function onKillFocus(n)
  46.    {
  47.       if(this._showingDropdown && n != null)
  48.       {
  49.          this.displayDropdown(false);
  50.       }
  51.       super.onKillFocus();
  52.    }
  53.    function getDropdown()
  54.    {
  55.       if(this.initializing)
  56.       {
  57.          return undefined;
  58.       }
  59.       if(!this.hasDropdown())
  60.       {
  61.          var _loc3_ = new Object();
  62.          _loc3_.styleName = this;
  63.          if(this.dropdownBorderStyle != undefined)
  64.          {
  65.             _loc3_.borderStyle = this.dropdownBorderStyle;
  66.          }
  67.          _loc3_._visible = false;
  68.          this.__dropdown = mx.managers.PopUpManager.createPopUp(this,mx.controls.List,false,_loc3_,true);
  69.          this.__dropdown.scroller.mask.removeMovieClip();
  70.          if(this.dataProvider == undefined)
  71.          {
  72.             this.dataProvider = new Array();
  73.          }
  74.          this.__dropdown.setDataProvider(this.dataProvider);
  75.          this.__dropdown.selectMultiple = false;
  76.          this.__dropdown.rowCount = this.__rowCount;
  77.          this.__dropdown.selectedIndex = this.selectedIndex;
  78.          this.__dropdown.vScrollPolicy = "auto";
  79.          this.__dropdown.labelField = this.__labelField;
  80.          this.__dropdown.labelFunction = this.__labelFunction;
  81.          this.__dropdown.owner = this;
  82.          this.__dropdown.changeHandler = this._changeHandler;
  83.          this.__dropdown.scrollHandler = this._scrollHandler;
  84.          this.__dropdown.itemRollOverHandler = this._itemRollOverHandler;
  85.          this.__dropdown.itemRollOutHandler = this._itemRollOutHandler;
  86.          this.__dropdown.resizeHandler = this._resizeHandler;
  87.          this.__dropdown.mouseDownOutsideHandler = function(eventObj)
  88.          {
  89.             if(!this.owner.hitTest(_root._xmouse,_root._ymouse,false))
  90.             {
  91.                if(!(!this.wrapDownArrowButton && this.owner.downArrow_mc.hitTest(_root._xmouse,_root._ymouse,false)))
  92.                {
  93.                   this.owner.displayDropdown(false);
  94.                }
  95.             }
  96.          };
  97.          this.__dropdown.onTweenUpdate = function(v)
  98.          {
  99.             this._y = v;
  100.          };
  101.          this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  102.          this.createObject("BoundingBox","mask",20);
  103.          this.mask._y = this.border_mc.height;
  104.          this.mask._width = this.__dropdownWidth;
  105.          this.mask._height = this.__dropdown.height;
  106.          this.mask._visible = false;
  107.          this.__dropdown.setMask(this.mask);
  108.       }
  109.       return this.__dropdown;
  110.    }
  111.    function setSize(w, h, noEvent)
  112.    {
  113.       super.setSize(w,h,noEvent);
  114.       this.__dropdownWidth = w;
  115.       this.__dropdown.rowHeight = h;
  116.       this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  117.    }
  118.    function setEditable(e)
  119.    {
  120.       super.setEditable(e);
  121.       if(e)
  122.       {
  123.          this.text_mc.setText("");
  124.       }
  125.       else
  126.       {
  127.          this.text_mc.setText(this.__get__selectedLabel());
  128.       }
  129.    }
  130.    function get labels()
  131.    {
  132.       return this.__labels;
  133.    }
  134.    function set labels(lbls)
  135.    {
  136.       this.__labels = lbls;
  137.       this.setDataProvider(lbls);
  138.    }
  139.    function getLabelField()
  140.    {
  141.       return this.__labelField;
  142.    }
  143.    function get labelField()
  144.    {
  145.       return this.getLabelField();
  146.    }
  147.    function setLabelField(s)
  148.    {
  149.       this.__dropdown.labelField = this.__labelField = s;
  150.       this.text_mc.setText(this.__get__selectedLabel());
  151.    }
  152.    function set labelField(s)
  153.    {
  154.       this.setLabelField(s);
  155.    }
  156.    function getLabelFunction()
  157.    {
  158.       return this.__labelFunction;
  159.    }
  160.    function get labelFunction()
  161.    {
  162.       return this.getLabelFunction();
  163.    }
  164.    function set labelFunction(f)
  165.    {
  166.       this.__dropdown.labelFunction = this.__labelFunction = f;
  167.       this.text_mc.setText(this.__get__selectedLabel());
  168.    }
  169.    function setSelectedItem(v)
  170.    {
  171.       super.setSelectedItem(v);
  172.       this.__dropdown.selectedItem = v;
  173.       this.text_mc.setText(this.__get__selectedLabel());
  174.    }
  175.    function setSelectedIndex(v)
  176.    {
  177.       super.setSelectedIndex(v);
  178.       this.__dropdown.selectedIndex = v;
  179.       this.text_mc.setText(this.__get__selectedLabel());
  180.       this.dispatchValueChangedEvent(this.getValue());
  181.    }
  182.    function setRowCount(count)
  183.    {
  184.       if(isNaN(count))
  185.       {
  186.          return undefined;
  187.       }
  188.       this.__rowCount = count;
  189.       this.__dropdown.setRowCount(count);
  190.    }
  191.    function get rowCount()
  192.    {
  193.       return Math.max(1,Math.min(this.length,this.__rowCount));
  194.    }
  195.    function set rowCount(v)
  196.    {
  197.       this.setRowCount(v);
  198.    }
  199.    function setDropdownWidth(w)
  200.    {
  201.       this.__dropdownWidth = w;
  202.       this.__dropdown.setSize(w,this.__dropdown.height);
  203.    }
  204.    function get dropdownWidth()
  205.    {
  206.       return this.__dropdownWidth;
  207.    }
  208.    function set dropdownWidth(v)
  209.    {
  210.       this.setDropdownWidth(v);
  211.    }
  212.    function get dropdown()
  213.    {
  214.       return this.getDropdown();
  215.    }
  216.    function setDataProvider(dp)
  217.    {
  218.       super.setDataProvider(dp);
  219.       this.__dropdown.setDataProvider(dp);
  220.       if(!this._editable)
  221.       {
  222.          this.selectedIndex = 0;
  223.       }
  224.    }
  225.    function open()
  226.    {
  227.       this.displayDropdown(true);
  228.    }
  229.    function close()
  230.    {
  231.       this.displayDropdown(false);
  232.    }
  233.    function get selectedLabel()
  234.    {
  235.       var _loc2_ = this.selectedItem;
  236.       if(_loc2_ == undefined)
  237.       {
  238.          return "";
  239.       }
  240.       if(this.__get__labelFunction() != undefined)
  241.       {
  242.          return this.__get__labelFunction()(_loc2_);
  243.       }
  244.       if(typeof _loc2_ != "object")
  245.       {
  246.          return _loc2_;
  247.       }
  248.       if(_loc2_[this.labelField] != undefined)
  249.       {
  250.          return _loc2_[this.labelField];
  251.       }
  252.       if(_loc2_.label != undefined)
  253.       {
  254.          return _loc2_.label;
  255.       }
  256.       var _loc3_ = " ";
  257.       for(var _loc4_ in _loc2_)
  258.       {
  259.          if(_loc4_ != "__ID__")
  260.          {
  261.             _loc3_ = _loc2_[_loc4_] + ", " + _loc3_;
  262.          }
  263.       }
  264.       _loc3_ = _loc3_.substring(0,_loc3_.length - 3);
  265.       return _loc3_;
  266.    }
  267.    function hasDropdown()
  268.    {
  269.       return this.__dropdown != undefined && this.__dropdown.valueOf() != undefined;
  270.    }
  271.    function tweenEndShow(value)
  272.    {
  273.       this._y = value;
  274.       this.isPressed = true;
  275.    }
  276.    function tweenEndHide(value)
  277.    {
  278.       this._y = value;
  279.       this.__set__visible(false);
  280.    }
  281.    function displayDropdown(show)
  282.    {
  283.       if(show == this._showingDropdown)
  284.       {
  285.          return undefined;
  286.       }
  287.       var _loc3_ = new Object();
  288.       _loc3_.x = 0;
  289.       _loc3_.y = this.height;
  290.       this.localToGlobal(_loc3_);
  291.       if(show)
  292.       {
  293.          this.getDropdown();
  294.          var _loc2_ = this.__dropdown;
  295.          _loc2_.isPressed = true;
  296.          _loc2_.rowCount = this.rowCount;
  297.          _loc2_.visible = show;
  298.          _loc2_.onTweenEnd = this.tweenEndShow;
  299.          var _loc5_ = undefined;
  300.          var _loc8_ = undefined;
  301.          if(_loc3_.y + _loc2_.height > Stage.height)
  302.          {
  303.             _loc5_ = _loc3_.y - this.__get__height();
  304.             _loc8_ = _loc5_ - _loc2_.height;
  305.             this.mask._y = - _loc2_.height;
  306.          }
  307.          else
  308.          {
  309.             _loc5_ = _loc3_.y - _loc2_.height;
  310.             _loc8_ = _loc3_.y;
  311.             this.mask._y = this.border_mc.height;
  312.          }
  313.          var _loc7_ = _loc2_.selectedIndex;
  314.          if(_loc7_ == undefined)
  315.          {
  316.             _loc7_ = 0;
  317.          }
  318.          var _loc4_ = _loc2_.vPosition;
  319.          _loc4_ = _loc7_ - 1;
  320.          _loc4_ = Math.min(Math.max(_loc4_,0),_loc2_.length - _loc2_.rowCount);
  321.          _loc2_.vPosition = _loc4_;
  322.          _loc2_.move(_loc3_.x,_loc5_);
  323.          _loc2_.tween = new mx.effects.Tween(this.__dropdown,_loc5_,_loc8_,this.getStyle("openDuration"));
  324.       }
  325.       else
  326.       {
  327.          delete this.__dropdown.dragScrolling;
  328.          this.__dropdown.onTweenEnd = this.tweenEndHide;
  329.          this.__dropdown.tween = new mx.effects.Tween(this.__dropdown,this.__dropdown._y,_loc3_.y - this.__dropdown.height,this.getStyle("openDuration"));
  330.       }
  331.       var _loc9_ = this.getStyle("openEasing");
  332.       if(_loc9_ != undefined)
  333.       {
  334.          this.__dropdown.tween.easingEquation = _loc9_;
  335.       }
  336.       this._showingDropdown = show;
  337.       this.dispatchEvent({type:(!show ? "close" : "open"),target:this});
  338.    }
  339.    function onDownArrow()
  340.    {
  341.       this._parent.displayDropdown(!this._parent._showingDropdown);
  342.    }
  343.    function keyDown(e)
  344.    {
  345.       if(e.ctrlKey && e.code == 40)
  346.       {
  347.          this.displayDropdown(true);
  348.       }
  349.       else if(e.ctrlKey && e.code == 38)
  350.       {
  351.          this.displayDropdown(false);
  352.       }
  353.       else if(e.code == 27)
  354.       {
  355.          this.displayDropdown(false);
  356.       }
  357.       else if(e.code == 13)
  358.       {
  359.          if(this._showingDropdown)
  360.          {
  361.             this.selectedIndex = this.__dropdown.selectedIndex;
  362.             this.displayDropdown(false);
  363.          }
  364.       }
  365.       else if(!this._editable || e.code == 38 || e.code == 40 || e.code == 33 || e.code == 34)
  366.       {
  367.          this.selectedIndex = 0 + this.selectedIndex;
  368.          this.bInKeyDown = true;
  369.          var _loc3_ = this.__get__dropdown();
  370.          _loc3_.keyDown(e);
  371.          this.bInKeyDown = false;
  372.          this.selectedIndex = this.__dropdown.selectedIndex;
  373.       }
  374.    }
  375.    function invalidateStyle(styleProp)
  376.    {
  377.       this.__dropdown.invalidateStyle(styleProp);
  378.       super.invalidateStyle(styleProp);
  379.    }
  380.    function changeTextStyleInChildren(styleProp)
  381.    {
  382.       if(this.dropdown.stylecache != undefined)
  383.       {
  384.          delete this.dropdown.stylecache[styleProp];
  385.          delete this.dropdown.stylecache.tf;
  386.       }
  387.       this.__dropdown.changeTextStyleInChildren(styleProp);
  388.       super.changeTextStyleInChildren(styleProp);
  389.    }
  390.    function changeColorStyleInChildren(sheetName, styleProp, newValue)
  391.    {
  392.       if(this.dropdown.stylecache != undefined)
  393.       {
  394.          delete this.dropdown.stylecache[styleProp];
  395.          delete this.dropdown.stylecache.tf;
  396.       }
  397.       this.__dropdown.changeColorStyleInChildren(sheetName,styleProp,newValue);
  398.       super.changeColorStyleInChildren(sheetName,styleProp,newValue);
  399.    }
  400.    function notifyStyleChangeInChildren(sheetName, styleProp, newValue)
  401.    {
  402.       if(this.dropdown.stylecache != undefined)
  403.       {
  404.          delete this.dropdown.stylecache[styleProp];
  405.          delete this.dropdown.stylecache.tf;
  406.       }
  407.       this.__dropdown.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  408.       super.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  409.    }
  410.    function onUnload()
  411.    {
  412.       this.__dropdown.removeMovieClip();
  413.    }
  414.    function _resizeHandler()
  415.    {
  416.       var _loc2_ = this.owner;
  417.       _loc2_.mask._width = this.width;
  418.       _loc2_.mask._height = this.height;
  419.    }
  420.    function _changeHandler(obj)
  421.    {
  422.       var _loc2_ = this.owner;
  423.       obj.target = _loc2_;
  424.       if(this != this.owner.text_mc)
  425.       {
  426.          _loc2_.selectedIndex = this.selectedIndex;
  427.          if(!_loc2_.bInKeyDown)
  428.          {
  429.             _loc2_.displayDropdown(false);
  430.          }
  431.       }
  432.       _loc2_.dispatchEvent(obj);
  433.    }
  434.    function _scrollHandler(obj)
  435.    {
  436.       var _loc2_ = this.owner;
  437.       obj.target = _loc2_;
  438.       _loc2_.dispatchEvent(obj);
  439.    }
  440.    function _itemRollOverHandler(obj)
  441.    {
  442.       var _loc2_ = this.owner;
  443.       obj.target = _loc2_;
  444.       _loc2_.dispatchEvent(obj);
  445.    }
  446.    function _itemRollOutHandler(obj)
  447.    {
  448.       var _loc2_ = this.owner;
  449.       obj.target = _loc2_;
  450.       _loc2_.dispatchEvent(obj);
  451.    }
  452.    function modelChanged(eventObj)
  453.    {
  454.       super.modelChanged(eventObj);
  455.       if(0 == this.__dataProvider.length)
  456.       {
  457.          this.text_mc.setText("");
  458.          delete this.selected;
  459.       }
  460.       else if(this.__dataProvider.length == eventObj.lastItem - eventObj.firstItem + 1 && eventObj.eventName == "addItems")
  461.       {
  462.          this.selectedIndex = 0;
  463.       }
  464.    }
  465. }
  466.